﻿Public Class clsLhPgd

    Public Function getListById(sys_id As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM sf.b_pgd_lh_details WHERE 1 = 1 and sys_id = ? "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, sys_id)
        If IsNothing(dt) Then
            getListById = New DataTable
        Else
            getListById = dt
        End If
    End Function

    Public Function getLhPgd() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.mes_project_code,b.start_time,b.end_time,c.prod_spec_name FROM sf.b_pgd_lh_details a "
        szSql &= "left join sf.b_pgd_mes b on a.b_pgd_mes_sys_id = b.sys_id "
        szSql &= "left join sf.t_prod_spec c on a.support_model = c.prod_spec_id "
        szSql &= " WHERE 1 = 1 "
        szSql &= " and a.factory_id = ? "
        szSql &= " and now() between b.start_time and b.end_time "
        szSql &= " and a.validity = ? "
        szSql &= " and a.lhj_finish_count < a.oper_count "
        szSql &= " ORDER BY a.oper_date ASC"
        Return DBacs.ExecuteSql(szSql, -1, "TS", "1")
    End Function

    Public Function getLHPlan() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.mes_project_code,b.type_value,b.start_time,b.end_time,c.prod_spec_name FROM sf.b_pgd_lh_details a "
        szSql &= "left join sf.b_pgd_mes b on a.b_pgd_mes_sys_id = b.sys_id "
        szSql &= "left join sf.t_prod_spec c on a.support_model = c.prod_spec_id "
        szSql &= " WHERE 1 = 1 "
        szSql &= " and a.factory_id = ? "
        szSql &= " and a.validity = ? "
        szSql &= " and a.lhj_finish_count_out < a.oper_count "
        szSql &= " and a.update_time > '2022/5/21 00:00:00.000'"
        szSql &= " ORDER BY a.oper_date ASC"
        Return DBacs.ExecuteSql(szSql, -1, "TS", "1")
    End Function

    Public Function updateLhj(lhj As String, Ope As String, id As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "UPDATE sf.b_pgd_lh_details set lhj = ?, operator = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " where sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, lhj, Ope, id)
            szSql = String.Empty
            szSql &= "INSERT INTO sf.b_pgd_lh_update_details(lhj, operator, update_time,b_pgd_lh_details_sys_id) "
            szSql &= "VALUES ( ? , ? , (SELECT CURRENT_TIMESTAMP(6)),?); "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, lhj, Ope, id)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
        End Try
        Return rtn
    End Function
End Class
